<?php

Class Mantra_mortar extends Connect {
    
    private $mantras = array();
    
    
    /**
     * $arr = errors
     *  4 = (Object)#2
      count = 0
      habar = "3"
      need = "10"
      array(''=>1);
      
    */
    function checkMantra($user, $arr){
        #return $arr;
        if(count(Mantra::$mantras['mortar']) == 0) return $arr;
        $this->mantras = array_shift(Mantra::$mantras['mortar']);
        
        $m = new Mantra($user);
        /*
        if(strftime('%d') != strftime($this->mantras['time'])){
            $m->_unuse($user, $user, $this->mantras);
            $m->_use($user, $user, $this->mantras);
        }
        */
        $need = 0;
        #$force = $this->mantras['force'] ;
        $force = $this->mantras['count'] ;
        foreach($arr as $key => $val){
            #if($key == 'need') 
            $need = $need + intval($val);
            $arr[$key] = max(0, intval($val) - $force );
            $force = $force - intval($val) ;
            if($force < 0){
                break;
            }                     
        }                
        
        #if($need <= $this->mantras['force']){              
        if($need <= $this->mantras['count']){
            
            $m->_unuse($user, $user, $this->mantras);
            #$this->mantras['force'] = floatval($this->mantras['force']) - $need;
            $this->mantras['count'] = floatval($this->mantras['count']) - $need;
            $m->_use($user, $user, $this->mantras);
            return array();
        }
        return $arr;          
    }        
}
?>